#include "GameAppPch.h"

#include "SectionManager.h"
#include "SectionTest.h"

SectionManager::SectionManager() :
m_curSectionID( SECTION_ID_MAX )
{

}

SectionManager::~SectionManager()
{

}

BOOL SectionManager::Init()
{
	m_pSectionList[SECTION_ID_TEST] = new SectionTest();

	return TRUE;
}

void SectionManager::UnInit()
{
	for(int cnt = 0; cnt < SECTION_ID_MAX; cnt++)
	{
		if( m_pSectionList[cnt] )
		{
			 m_pSectionList[cnt]->UnInit();
			 delete m_pSectionList[cnt];
		}	
	}
}

void SectionManager::Update(float TimeDelta)
{
	if( m_curSectionID < SECTION_ID_MAX )
	{
		if( m_pSectionList[m_curSectionID] )
		{
			 m_pSectionList[m_curSectionID]->Update( TimeDelta );
		}	
	}
}

void SectionManager::Render()
{
	if( m_curSectionID < SECTION_ID_MAX )
	{
		if( m_pSectionList[m_curSectionID] )
		{
			 m_pSectionList[m_curSectionID]->Render();
		}	
	}
}

void SectionManager::HandleEvent( UINT message, WPARAM wParam, LPARAM lParam )
{
	if( m_curSectionID < SECTION_ID_MAX )
	{
		if( m_pSectionList[m_curSectionID] )
		{
			 m_pSectionList[m_curSectionID]->HandleEvent(message, wParam, lParam);
		}	
	}
}

void SectionManager::ProcessGUIMessage( GUIMessage & msg )
{
	if( m_curSectionID < SECTION_ID_MAX )
	{
		if( m_pSectionList[m_curSectionID] )
		{
			 m_pSectionList[m_curSectionID]->ProcessGUIMessage( msg );
		}	
	}
}

void SectionManager::ConnectSection( SECTION_ID sectionID )
{
	if( sectionID >= SECTION_ID_MAX )
	{
		return;
	}

	if( m_curSectionID < SECTION_ID_MAX )
	{
		if( m_pSectionList[m_curSectionID] )
		{
			 m_pSectionList[m_curSectionID]->UnInit();
		}	
	}

	m_pSectionList[sectionID]->Init();
	m_curSectionID = sectionID;
}